package com.zucc.controller;

import com.zucc.controller.req.DeviceAddReq;
import com.zucc.controller.req.DeviceModifyReq;
import com.zucc.controller.req.DeviceSearchReq;
import com.zucc.controller.resp.DeviceResp;
import com.zucc.service.DeviceService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-23 5:36 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/devices")
@Api(tags = "设备管理")
public class DeviceController {
    @Resource
    private DeviceService deviceService;

    @ApiOperation(value = "导入设备表格--暂不验证 领用人是否存在")
    @PostMapping("/import")
    void importDeviceExcel(MultipartFile file) {
        deviceService.importDeviceExcel(file);
    }

    @ApiOperation(value = "新增设备")
    @PostMapping
    void add(@RequestBody @Validated DeviceAddReq req) {
        deviceService.add(req);
    }

    @ApiOperation(value = "修改设备")
    @PutMapping
    void modify(@RequestBody @Validated DeviceModifyReq req) {
        deviceService.modify(req);
    }

    @ApiOperation(value = "删除设备")
    @ApiImplicitParam(paramType = "path", name = "id", value = "设备编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        deviceService.deleteOne(id);
    }

    @ApiOperation(value = "设备分页")
    @PostMapping("/page")
    PageData<DeviceResp> page(@RequestBody @Validated DeviceSearchReq req) {
        return deviceService.page(req);
    }

}
